<include file="Public/header" title="{$Think.config.PWD_NAME}" />
<include file="Public/navbar" />
<div class="container">
    <h3>生成随机密码</h3>
    <form action="" method="post">
    <div class="form-group">
        <label for="include_number"><span>数字</span></label>
        <input type="checkbox" id="include_number" checked="checked" >
    </div>
    <div class="form-group">
        <label for="include_lowercaseletters"><span>小写字母</span></label>
        <input type="checkbox" id="include_lowercaseletters" checked="checked" >
    </div>
    <div class="form-group">
        <label for="include_uppercaseletters"><span>大写字母</span></label>
        <input type="checkbox" id="include_uppercaseletters" >
    </div>
    <div class="form-group">
        <label for="include_punctuation"><span>标点符号</span></label>
        <input type="checkbox" id="include_punctuation" >
    </div>
    <div class="form-group">
        <label for="pwd_unique"><span>字符不重复</span></label>
        <input type="checkbox" id="pwd_unique" checked="checked" >
    </div>
    <div class="form-group">
        <label for="pwd_length"><span>密码长度</span></label>
        <input type="number" class="form-control" id="pwd_length" value="8">
    </div>
    <div class="form-group">
        <label for="pwd_quantity"><span>密码数量</span></label>
        <input type="number" class="form-control" id="pwd_quantity" value="1">
    </div>
    <div class="form-group">
        <button id="generate" class="btn btn-primary">生成密码</button>
    </div>
    <div class="form-group">
        <textarea id="output" class="form-control" cols="40" rows="7" readonly="readonly"></textarea>
    </div>
    </form>
</div>
<script type="text/javascript">
jQuery(function($) {
	function rand(max) {
		return Math.floor(Math.random() * max);
	};
	$('#generate').click(function() {
		var chars = "";
		if($('#include_number').is(':checked')) {
			chars += "0123456789";
		}
		if($('#include_lowercaseletters').is(':checked')) {
			chars += "abcdefghijklmnopqrstuvwxyz";
		}
		if($('#include_uppercaseletters').is(':checked')) {
			chars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		}
		if($('#include_punctuation').is(':checked')) {
			chars += "`~!@#$%^&*()-_=+[{]}\|;:'\\\",<.>/?";
		}
		var pwd_unique = $('#pwd_unique').is(':checked');
		var pwd_length = $('#pwd_length').val();
		var pwd_quantity = $('#pwd_quantity').val();
		var pwds = [];
		for(var i=0; i<pwd_quantity; i++) {
			var _chars = chars.split(""),
			pwd = "";
			for(var j=0; j<pwd_length; j++) {
				if(1 > _chars.length) {
					break;
				}
				var index = rand(_chars.length);
				pwd += _chars[index];
				if(pwd_unique) {
					_chars.splice(index, 1);
				}
			}
			pwds.push(pwd);
		}
		var output = pwds.join("\n");
		$('#output').val(output);
		return false;
	});
	$('#output').focus(function() {
		$(this).select();
	});
});
</script>
<include file="Public/footer" />